<template>
  <div class="layout_addprogram">
    <div class="row">
      <Icon type="ios-arrow-right" class="select-icon"></Icon>
      <label for>项 目 分 类：</label>
      <cube-select
        v-model="project_type"
        :options="project_type_arr"
        placeholder="请选择项目类别"
        @change="change_project_type"
      ></cube-select>
    </div>
    <div class="row">
      <Icon type="ios-arrow-right" class="select-icon"></Icon>
      <label for>项 目 名 称：</label>
      <cube-select
        v-model="project_id"
        @change="change_project"
        :options="option_program"
        placeholder="请选择项目名称"
      ></cube-select>
    </div>
    <div class="row" v-if="is_other">
      <label>
        &nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </label>
      <input type="text" v-model="project_name" maxlength="20" placeholder="请输入项目名称" />
    </div>
    <div class="row">
      <Icon type="ios-arrow-right" class="select-icon"></Icon>
      <label for>手 术 医 生：</label>
      <cube-select v-model="doc_name" :options="doc_arr" placeholder="请选择手术医生 (非必填)"></cube-select>
    </div>
    <cube-button @click="showDatePicker">
      手 术 时 间 ：
      <span v-text="billDate"></span>
    </cube-button>

    <div class="row">
      <label>剩余消费金额:</label>
      <input type="tel" v-model="total_price" readonly />
    </div>
    <div class="row">
      <label>剩余奖励金额:</label>
      <input type="tel" v-model="reward_price" readonly />
    </div>

    <div class="row">
      <label>消费总金额:</label>
      <input
        type="tel"
        v-model="total_money"
        @change="change_total_money()"
        maxlength="7"
        placeholder="请输入补贴单消费总金额"
        :readonly="readonly"
      />
      <!-- placeholder="请输入补贴单消费总金额" -->
    </div>
    <div class="row cost" v-if="form_type==0">
      <label>奖励金额:</label>
      <input
        type="tel"
        v-model="progarmAmount"
        @change="change_money()"
        maxlength="7"
        placeholder="请输入补贴单奖励总金额"
        :readonly="readonly"
      />
      <!-- placeholder="请输入补贴单奖励总金额" -->
      <!-- <p class="tip">注：扣除杂费金额=消费总金额-杂费</p> -->
    </div>
    <div class="row cost" v-if="form_type==1">
      <label>奖励金额（无补贴）:</label>
      <input
        style="width:50%"
        type="tel"
        v-model="progarmAmount"
        @change="change_money()"
        maxlength="7"
        placeholder="请输入补贴单奖励金额"
        :readonly="readonly"
      />
      <!-- placeholder="请输入补贴单奖励总金额" -->
    </div>
    <div>
      <div class="row">
        <label>项目实际扣除:</label>
        <div class="num">
          <span>现金金额{{applyInfor.cash_money_price}}</span>
          <span>金币{{applyInfor.gold_coin}}</span>
        </div>
      </div>
      <div class="gray"></div>
    </div>
    <div v-if="form_type==0">
      <div class="row">
        <label>金币补贴:</label>
        <input type="tel" v-model="cash_allowance" maxlength="7" />
      </div>
      <div class="row">
        <label>银币补贴:</label>
        <input type="tel" v-model="integral_allowance" maxlength="7" />
      </div>
      <div class="gray"></div>
    </div>

    <!-- 保险选择 -->
    <div v-if="form_type==0">
      <div class="row" v-if="this.is_need_insure">
        <Icon type="ios-arrow-right" class="select-icon"></Icon>
        <label for>保 险 类 别：</label>
        <cube-select v-model="insure_type" :options="insure_type_options" placeholder="请选择保险类别"></cube-select>
      </div>

      <div class="row" @click="showBirthDatePicker">
        <label>出 生 日 期 ：</label>
        <span v-text="birthdate"></span>
      </div>
    </div>

    <div class="gray"></div>
    <div class="uploadMoudle">
      <p>上传消费凭证（最多上传9张）：</p>
      <cube-upload
        :action="action"
        :max="9"
        @files-added="filesAddedOrder"
        @file-success="fileSuccessOrder"
        @file-removed="fileRemovedOrder"
      />
    </div>
    <div class="gray"></div>
    <div class="uploadMoudle">
      <p>上传手术照片（至少上传2张）：</p>
      <cube-upload
        :action="action"
        :max="9"
        @files-added="filesAdded"
        @file-success="fileSuccess"
        @file-removed="fileRemoved"
      />
    </div>
    <div class="gray"></div>
    <div class="note">
      <div>备注:</div>
      <cube-textarea v-model="value" placeholder :maxlength="255"></cube-textarea>
    </div>
    <button @click="createdBill()" :disabled="isdisabledBtn">提交</button>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import api from "../../assets/js/api";
let timer;
export default {
  data() {
    return {
      //管家1.7新增
      cash_allowance: "", //现金补贴
      integral_allowance: "", //积分补贴
      total_money: "", // 消费总金额
      hospital: "",
      programName: "",
      option_program: [],
      billDate: "", //手术日期
      join_birthdate: "", //参数读取在出生日期
      birthdate: "", //出生日期
      progarmAmount: "",
      introduction: "",
      pickerVisible: "", //选择器
      operationAmount: "",
      // selected: "", //是否首单
      options: [
        {
          label: "是",
          value: "1"
        },
        {
          label: "否",
          value: "0"
        }
      ],
      value: "",
      placeholder: "",
      action: {
        // 正式服
        target: "https://act.yuepinyuemei.com/api/upload/img",

        data: {
          dirPath: "order"
        }
      },
      photo4: [], //消费凭证
      photo5: [], //对比照
      str4: "",
      str5: "",
      order_sn: "",
      cardTime: "",
      isdisabledBtn: false,
      isopen: false,
      credit: "",
      pay_num: "",
      btn_msg: "获取验证码",
      num: 60,
      credit_all: "",
      project_type_arr: [],
      project_type: "",
      project_id: "",
      project_name: "",
      doc_name: "",
      is_other: false,
      doc_arr: [],

      // 保险数据
      is_need_insure: 1,
      form_type: null, //报单类型 0：美美咖报单 1：传统报单
      insure_type: 0,
      insure_type_options: [
        {
          text: "微整型",
          value: "1"
        },
        {
          text: "皮肤美容",
          value: "2"
        },
        {
          text: "私密整型",
          value: "3"
        },
        {
          text: "眼部整型",
          value: "4"
        },
        {
          text: "鼻部整型",
          value: "5"
        },
        {
          text: "自体脂肪",
          value: "6"
        },
        {
          text: "美体塑形",
          value: "7"
        },
        {
          text: "面部轮廓",
          value: "8"
        },
        {
          text: "乳房整型",
          value: "9"
        },
        {
          text: "无保险",
          value: "10"
        }
      ],
      // 1.8.9
      total_price: null, //剩余消费金额
      reward_price: null, //剩余奖励金额
      applyInfor: {},
      valid_gold_coin: "",
      readonly:false
    };
  },
  created() {
    document.title = "添加项目";
    this.axios.defaults.baseURL = api;
    this.order_sn = location.hash.split(":")[1];
    this.is_need_insure = location.hash.split(":")[2] || 0;

    let my_birthdate = location.hash.split(":")[3] || "";
    let form_type = location.hash.split(":")[4] || "";
    this.birthdate = my_birthdate;
    this.join_birthdate = my_birthdate;
    this.form_type = form_type;
    let orderType = location.hash.split(":")[5] || "";
    console.log(
      "流水单单号=>",
      this.order_sn,
      "保险是否必填=>",
      this.is_need_insure,
      "出生年月=>",
      this.birthdate,
      "报单类型=>",
      form_type
    );
    if (orderType > 3) {
      this.readonly=true
      this.applyInfo();
    }
    // this.applyInfo()
    this.get_project_list();
    this.credit_all = sessionStorage.getItem("user_credit");
    this.hospital = sessionStorage.getItem("hospital_id");
    this.get_program();
    this.get_doctor();
    console.log(this.credit_all);
    this.get_reward();
  },
  filters: {},
  methods: {
    applyInfo() {
      this.axios
        .post("api/butler/apply_info", {
          order_sn: this.order_sn
        })
        .then(msg => {
          if (msg.data.code == 200) {
            console.log(200, msg.data.data);
            this.applyInfor = msg.data.data;
            this.total_money = this.applyInfor.total_price.toString();
            this.progarmAmount = this.applyInfor.reward_price.toString();
            this.cash_allowance = this.applyInfor.cash_allowance.toString();
            this.integral_allowance = this.applyInfor.silver_coin.toString();
          } else if (msg.data.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            Toast({
              message: msg.data.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          console.log(error);

          Toast({
            message: "请求错误，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    // 获取剩余消费金额和奖励金额（新增）
    get_reward() {
      let loading = this.loading("加载中", 60000);
      loading.show();
      this.axios
        .post("api/butler/get_reward", {
          order_sn: this.order_sn
        })
        .then(msg => {
          loading.hide();
          if (msg.data.code == 200) {
            // console.log(200,msg)
            this.total_price = msg.data.data.total_price;
            this.reward_price = msg.data.data.reward_price;
            this.valid_gold_coin = msg.data.data.valid_gold_coin;
          } else if (msg.data.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            Toast({
              message: msg.data.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          console.log(error);

          Toast({
            message: "请求错误，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    //判断该流水单是否需要必填保险类别
    change_insure() {},
    change_project() {
      this.project_name = "";
      this.option_program.forEach(item => {
        if (item.id == this.project_id) {
          if (item.name.includes("其他")) {
            this.is_other = true;
          } else {
            this.is_other = false;
            this.project_name = item.name;
          }
        }
      });
    },
    get_project_list() {
      let loading = this.loading("加载中", 60000);
      loading.show();
      this.axios
        .post("api/butler/project/type")
        .then(msg => {
          loading.hide();
          if (msg.data.code == 200) {
            let arr = msg.data.data;
            arr.forEach(el => {
              el.value = el.id;
              el.text = el.name;
            });
            this.project_type_arr = arr;
          } else if (msg.data.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            Toast({
              message: msg.data.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          console.log(error);
          Toast({
            message: "请求错误，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    change_project_type() {},

    change_money() {
      if (Number(this.progarmAmount) < Number(this.valid_gold_coin)) {
        this.applyInfor.gold_coin = this.progarmAmount;
        this.applyInfor.cash_money_price = "0";
      } else if (Number(this.progarmAmount) >= Number(this.valid_gold_coin)) {
        this.applyInfor.gold_coin = this.valid_gold_coin;
        this.applyInfor.cash_money_price =
          this.progarmAmount - this.applyInfor.gold_coin;
      }
      this.$forceUpdate();

      this.credit =
        this.progarmAmount - 0 < this.credit_all - 0
          ? this.progarmAmount - 0
          : this.credit_all - 0;
      this.pay_num = this.progarmAmount - 0 - this.credit;
      console.log(154,this.applyInfor.cash_money_price-0)
      if (this.applyInfor.cash_money_price == 0) {
        this.cash_allowance = '0'; //现金补贴
        this.integral_allowance = '0';
      }

      if(this.applyInfor.cash_money_price>0){
        this.getApplyMoney(); //获取补贴金额
      }
      
    },
    get_program() {
      let loading = this.loading("加载中", 60000);
      loading.show();
      this.axios
        .post("api/butler/getProject", {
          hospital: this.hospital
        })
        .then(msg => {
          loading.hide();
          if (msg.data.code == 200) {
            var arr = msg.data.data;
            if (arr.length > 0) {
              arr.forEach(el => {
                el.value = el.id;
                el.text = el.name;
              });
              this.option_program = arr;
              this.other_id = arr[arr.length - 1].id;
            } else {
              Toast({
                message: "该医院暂无项目",
                position: "bottom",
                duration: 2000
              });
            }
          } else if (msg.data.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            Toast({
              message: msg.data.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          console.log(error);

          Toast({
            message: "请求错误，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    showDatePicker() {
      if (!this.datePicker) {
        this.datePicker = this.$createDatePicker({
          title: "日期",
          min: new Date(
            new Date().getFullYear(),
            new Date().getMonth() - 2,
            new Date().getDate()
          ),
          max: new Date(new Date().getFullYear(), 11, 31),
          value: new Date(),
          onSelect: this.selectHandle,
          onCancel: this.cancelHandle
        });
      }
      this.datePicker.show();
    },
    selectHandle(date, selectedVal, selectedText) {
      this.billDate = selectedText.join("-");
    },

    //选择出生日期
    showBirthDatePicker() {
      console.log("===>", this.join_birthdate);

      if (this.join_birthdate != "") {
        return false;
      }

      if (!this.datePicker2) {
        this.datePicker2 = this.$createDatePicker({
          title: "日期",
          min: new Date("1900", "0", "01"),
          max: new Date(new Date().getFullYear(), 11, 31),
          value: new Date(),
          onSelect: this.dateSelectHandle,
          onCancel: this.cancelHandle
        });
      }
      this.datePicker2.show();
    },
    //选择出生日期的选择回调
    dateSelectHandle(date, selectedVal, selectedText) {
      this.birthdate = selectedText.join("-");
    },

    isFirstSelect(text) {},
    filesAddedOrder(files) {
      //消费凭证
      let hasIgnore = false;
      const maxSize = 20 * 1024 * 1024; // 20M
      for (let k in files) {
        const file = files[k];
        if (file.size > maxSize) {
          file.ignore = true;
          hasIgnore = true;
        }
      }
      hasIgnore &&
        this.$createToast({
          type: "warn",
          time: 1000,
          txt: "图片上传失败，不能大于20M"
        }).show();
    },
    fileSuccessOrder(file) {
      this.str4 += file.response.data.url + "#";
    },
    //图片删除的回调
    fileRemovedOrder(file) {
      console.log("图片上传地址", this.str4);
      let curStr4 = this.str4;
      let removeFileUrl = file.response.data.url;

      if (curStr4 && removeFileUrl) {
        let picArray = curStr4.split("#");
        if (picArray) {
          console.log("删除前的数组为", picArray);
          let index = picArray.indexOf(removeFileUrl);
          picArray.splice(index, 1);
          // picArray.remove(removeFileUrl)
          console.log("删除后的数组为", picArray);

          curStr4 = picArray.join("#");
          console.log("图片上传地址删除后", curStr4);
          this.str4 = curStr4;
        }
      }
    },

    filesAdded(files) {
      //对比照
      this.photo5 = files;
      let hasIgnore = false;
      const maxSize = 20 * 1024 * 1024; // 2M
      for (let k in files) {
        const file = files[k];
        if (file.size > maxSize) {
          file.ignore = true;
          hasIgnore = true;
        }
      }
      hasIgnore &&
        this.$createToast({
          type: "warn",
          time: 3000,
          txt: "图片上传失败，不能大于20M"
        }).show();
    },
    fileSuccess(file) {
      this.str5 += file.response.data.url + "#";
    },
    //图片删除的回调 (手术照片)
    fileRemoved(file) {
      console.log("图片上传地址", this.str4);
      let curStr5 = this.str5;
      let removeFileUrl = file.response.data.url;

      if (curStr5 && removeFileUrl) {
        let picArray = curStr5.split("#");
        if (picArray) {
          console.log("删除前的数组为", picArray);
          let index = picArray.indexOf(removeFileUrl);
          picArray.splice(index, 1);
          // picArray.remove(removeFileUrl)
          console.log("删除后的数组为", picArray);

          curStr5 = picArray.join("#");
          console.log("图片上传地址删除后", curStr5);
          this.str5 = curStr5;
        }
      }
    },
    addTextarea(e) {},
    // 美美咖报单
    mmkBill(e) {
      console.log("hhaha=>", this.insure_type);
      this.order_sn = location.hash.split(":")[1];
      if (this.project_type == "") {
        Toast({
          message: "请选择项目类型",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.project_id == "") {
        Toast({
          message: "请选择项目名称",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.is_other && this.project_name == "") {
        Toast({
          message: "请填写项目名称",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.billDate == "") {
        Toast({
          message: "请选择手术时间",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.total_money.trim() == "") {
        Toast({
          message: "请填写消费总金额",
          position: "bottom",
          duration: 2000
        });
      } else if (this.progarmAmount.trim() == "") {
        Toast({
          message: "请填写扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.progarmAmount <= 0) {
        Toast({
          message: "请填写正确的扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.cash_allowance.trim() == "") {
        Toast({
          message: "请填写现金补贴",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.integral_allowance.trim() == "") {
        Toast({
          message: "请填写积分补贴",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.insure_type == 0 && this.is_need_insure == 1) {
        Toast({
          message: "请选择保险类别",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.birthdate == "") {
        Toast({
          message: "请选择出生日期",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str4 == "") {
        Toast({
          message: "请上传消费凭证",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str4.split("#")[0] == "undefined") {
        Toast({
          message: "请重新上传消费凭证",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str5.split("#").length < 3) {
        Toast({
          message: "手术照片至少上传两张",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str5.split("#")[0] == "undefined") {
        Toast({
          message: "请重新上传手术照片",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.total_money - this.progarmAmount < 0) {
        console.log(this.total_money, this.progarmAmount);
        Toast({
          message: "消费总金额必须大于扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.value.trim == "") {
        Toast({
          message: "请填写备注",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else {
        //检测 几个金额之间的关系！！
        let tmp_cash_allowance = parseFloat(this.cash_allowance);
        let tmp_integral_allowance = parseFloat(this.integral_allowance);
        let tmp_progarmAmount = parseFloat(this.progarmAmount);
        console.log(
          "按照顺序的三个参数",
          tmp_cash_allowance,
          tmp_integral_allowance,
          tmp_progarmAmount
        );
        if (tmp_cash_allowance + tmp_integral_allowance > tmp_progarmAmount) {
          Toast({
            message: "现金补贴加积分补贴 不能大于 扣除杂费金额",
            position: "bottom",
            duration: 2000
          });
          return false;
        }

        this.isdisabledBtn = true;
        let load = this.loading("加载中");
        load.show();
        this.axios
          .post("/api/butler/apply_add", {
            total_money: this.total_money,
            order_sn: this.order_sn,
            project_type_id: this.project_type,
            project_id: this.project_id,
            project_name: this.project_name,
            operation_time: this.billDate,
            money: this.applyInfor.cash_money_price,
            img4: this.str4, //消费凭证
            img5: this.str5, //手术前后照
            remark: this.value,
            doctor_id: this.doc_name,
            //新增的 现金补贴 + 积分补贴
            cash_allowance: this.cash_allowance - 0,
            integral_allowance: this.integral_allowance - 0,
            insure_type: this.insure_type,
            birthdate: this.birthdate,
            gold_coin: this.applyInfor.gold_coin
          })
          .then(msg => {
            this.isdisabledBtn = false;
            if (msg.data.code == 200) {
              window.sessionStorage.removeItem("pindex"); //移除项目列表位置栏
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
              this.$router.go(-1);
            } else if (msg.data.code == 250) {
              Toast({
                message: "登录过期，请重新登陆",
                position: "bottom",
                duration: 2000
              });
              this.$router.push("/login");
              return false;
            } else {
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
            }
            load.hide();
          })
          .catch(error => {
            console.log(error);
            load.hide();
            this.isdisabledBtn = false;
            Toast({
              message: "请求失败，请稍后重试",
              position: "bottom",
              duration: 2000
            });
          });
      }
    },
    // 传统报单
    traditional(e) {
      console.log("hhaha=>", this.insure_type);
      this.order_sn = location.hash.split(":")[1];
      if (this.project_type == "") {
        Toast({
          message: "请选择项目类型",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.project_id == "") {
        Toast({
          message: "请选择项目名称",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.is_other && this.project_name == "") {
        Toast({
          message: "请填写项目名称",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.billDate == "") {
        Toast({
          message: "请选择手术时间",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.total_money.trim() == "") {
        Toast({
          message: "请填写消费总金额",
          position: "bottom",
          duration: 2000
        });
      } else if (this.progarmAmount.trim() == "") {
        Toast({
          message: "请填写扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.progarmAmount <= 0) {
        Toast({
          message: "请填写正确的扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str4 == "") {
        Toast({
          message: "请上传消费凭证",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str4.split("#")[0] == "undefined") {
        Toast({
          message: "请重新上传消费凭证",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str5.split("#").length < 3) {
        Toast({
          message: "手术照片至少上传两张",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.str5.split("#")[0] == "undefined") {
        Toast({
          message: "请重新上传手术照片",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.total_money - this.progarmAmount < 0) {
        console.log(this.total_money, this.progarmAmount);
        Toast({
          message: "消费总金额必须大于扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else if (this.value.trim == "") {
        Toast({
          message: "请填写备注",
          position: "bottom",
          duration: 2000
        });
        return false;
      } else {
        //检测 几个金额之间的关系！！
        let tmp_cash_allowance = parseFloat(this.cash_allowance);
        let tmp_integral_allowance = parseFloat(this.integral_allowance);
        let tmp_progarmAmount = parseFloat(this.progarmAmount);
        console.log(
          "按照顺序的三个参数",
          tmp_cash_allowance,
          tmp_integral_allowance,
          tmp_progarmAmount
        );
        if (tmp_cash_allowance + tmp_integral_allowance > tmp_progarmAmount) {
          Toast({
            message: "现金补贴加积分补贴 不能大于 扣除杂费金额",
            position: "bottom",
            duration: 2000
          });
          return false;
        }

        this.isdisabledBtn = true;
        let load = this.loading("加载中");
        load.show();
        this.axios
          .post("/api/butler/apply_add_tradition", {
            total_money: this.total_money,
            order_sn: this.order_sn,
            project_type_id: this.project_type,
            project_id: this.project_id,
            project_name: this.project_name,
            operation_time: this.billDate,
            money: this.applyInfor.cash_money_price,
            img4: this.str4, //消费凭证
            img5: this.str5, //手术前后照
            remark: this.value,
            doctor_id: this.doc_name,
            gold_coin: this.applyInfor.gold_coin
          })
          .then(msg => {
            this.isdisabledBtn = false;
            if (msg.data.code == 200) {
              window.sessionStorage.removeItem("pindex"); //移除项目列表位置栏
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
              this.$router.go(-1);
            } else if (msg.data.code == 250) {
              Toast({
                message: "登录过期，请重新登陆",
                position: "bottom",
                duration: 2000
              });
              this.$router.push("/login");
              return false;
            } else {
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
            }
            load.hide();
          })
          .catch(error => {
            console.log(error);
            load.hide();
            this.isdisabledBtn = false;
            Toast({
              message: "请求失败，请稍后重试",
              position: "bottom",
              duration: 2000
            });
          });
      }
    },
    createdBill(e) {
      if (this.form_type == 0) {
        this.mmkBill(e);
      }
      if (this.form_type == 1) {
        this.traditional(e);
      }
    },
    selectTime(date, selectedVal, selectedText) {
      if (!this.dateTimePicker) {
        this.dateTimePicker = this.$createDatePicker({
          title: "请选择刷卡时间",
          min: new Date(new Date().getFullYear(), 0, 1, 0, 0, 0),
          max: new Date(new Date().getFullYear(), 5, 31, 23, 59, 59),
          value: new Date(),
          columnCount: 6,
          onSelect: (date, selectedVal, selectedText) => {
            let timeArr = selectedVal,
              tostring;
            timeArr[1] = timeArr[1] - 0 < 0 ? "0" + timeArr[1] : timeArr[1];
            timeArr[2] = timeArr[2] < 0 ? "0" + timeArr[2] : timeArr[2];
            timeArr[3] = timeArr[3] < 0 ? "0" + timeArr[3] : timeArr[3];
            timeArr[4] = timeArr[4] < 0 ? "0" + timeArr[4] : timeArr[4];
            timeArr[5] = timeArr[5] < 0 ? "0" + timeArr[5] : timeArr[5];
            tostring =
              timeArr[0] +
              "-" +
              timeArr[1] +
              "-" +
              timeArr[2] +
              " " +
              timeArr[3] +
              ":" +
              timeArr[4] +
              ":" +
              timeArr[5];
            this.cardTime = tostring;
          },
          onCancel: this.cancelTime
        });
      }
      this.dateTimePicker.show();
    },

    cancelTime() {
      this.cardTime = "";
    },
    change_total_money() {
      this.cash_allowance = ""; //现金补贴
      this.integral_allowance = ""; //积分补贴
      this.progarmAmount = ""; //补贴总金额
    },
    get_doctor() {
      this.axios
        .post("api/butler/doctor/list", {
          hospital: this.hospital
        })
        .then(result => {
          let res = result.data;
          if (res.code == 200) {
            let arr = res.data.doctors || [];
            arr.forEach(item => {
              item.text = item.name;
              item.value = item.id;
            });
            this.doc_arr = arr;
          } else {
            Toast({
              message: res.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(err => {
          console.log(err);
          Toast({
            message: "服务器出错啦",
            position: "bottom",
            duration: 2000
          });
        });
    },

    //获取补贴金额
    getApplyMoney() {
      this.axios
        .post("api/butler/apply/money", {
          order_sn: this.order_sn,
          money: this.applyInfor.cash_money_price
        })
        .then(result => {
          let res = result.data;
          if (res.code == 200) {
            this.cash_allowance = "" + res.data.cash_allowance; //现金补贴
            this.integral_allowance = "" + res.data.integral_allowance; //积分补贴
          } else {
            Toast({
              message: res.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(err => {
          console.log(err);
          Toast({
            message: "服务器出错啦",
            position: "bottom",
            duration: 2000
          });
        });
    }
  }
};
</script>





<style scoped lang="less">
.layout_addprogram {
  width: 100%;
  height: 100%;
  overflow: auto;
  font-size: 17px;
  color: #666;
  text-align: center;
  margin: 0 auto;
  /* background:rgba(204,204,204,.2018); */
}

.isFinis {
  height: 48px;
  width: 100%;
  line-height: 48px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
  padding-left: 15px;
  font-size: 16px;
  color: #666;
  text-align: left;
}

.uploadMoudle {
  margin-top: 10px;
  background-color: #fff;
  padding: 13px 15px;
}
.uploadMoudle p {
  font-size: 16px;
  text-align: left;
  margin-bottom: 13px;
}

.isFirstSelect {
  height: 48px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
  display: flex;
  background-color: #fff;
  padding-left: 15px;
}
.isFirstSelect label {
  height: 48px;
  line-height: 48px;
}

.note {
  width: 100%;
  background-color: #fff;
  text-align: left;
  padding: 0 15px;
  font-size: 17px;
  color: #666;
  margin-top: 10px;
}

.row {
  min-height: 48px;
  line-height: 48px;
  width: 100%;
  background-color: #fff;
  text-align: left;
  padding-left: 15px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
  position: relative;
  display: flex;
  align-items: center;
}

.row input {
  height: 46px;
  margin-bottom: 2px;
  background-color: #fff;
  font-size: 17px;
  padding-left: 10px;
  color: #888888;
}
.row > span {
  color: #888888;
}

.gray {
  width: 100%;
  height: 10px;
  background: rgba(204, 204, 204, 0.2018);
}
.cube-btn {
  height: 48px !important;
  min-width: 70% !important;
  background: #fff !important;
  color: #666 !important;
  text-align: left !important;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
  padding: 17px 15px !important;
  float: left;
}
.cube-radio {
  display: inline-block !important;
}
.cube-radio-group {
  display: flex !important;
}
.cube-radio_selected .cube-radio-ui {
  background-color: #d8d8d8 !important;
}
.mint-field:nth-last-of-type(1) {
  border-bottom: none !important;
}

.cube-textarea::placeholder {
  color: #fff !important;
}
.cube-select::after {
  border: 0 !important;
}
.cube-select {
  width: 71% !important;
  line-height: 1.9 !important;
}
.cube-picker-confirm {
  color: #999;
}
</style>

<style lang="less">
.layout_addprogram {
  .cube-select-icon {
    display: none !important;
  }
  .select-icon {
    display: block;
    font-size: 20px;
    position: absolute !important;
    right: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 99;
  }
  .time-btn {
    width: 50%;
  }
  .cube-textarea-wrapper,
  .cube-textarea {
    min-height: 120px !important;
    border-color: rgba(204, 204, 204, 1);
  }
  .cost {
    display: inline-block;
    .tip {
      color: #ccc;
      margin-top: -25px;
    }
  }
  .credit {
    .cube-switch {
      position: absolute;
      top: 50%;
      right: 15px;
      transform: translateY(-50%);
    }
    .cube-switch .cube-switch-input:checked + .cube-switch-ui {
      background-color: #09bb07;
      border-color: #09bb07;
    }
  }
  .check_num {
    .get-msg {
      height: 32px;
      line-height: 32px;
      padding: 0 15px;
      text-align: center;
      border-radius: 16px;
      border: 1px solid rgba(204, 204, 204, 1);
      font-size: 14px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      position: absolute;
      right: 15px;
      top: 50%;
      transform: translateY(-50%);
    }
  }
  ::placeholder,
  .cube-select-placeholder {
    font-size: 17px;
    font-family: "PingFangSC-Regular";
    font-weight: 400;
    color: rgba(204, 204, 204, 1);
  }
}
.num {
  color: #888888;
  padding: 0 10px;
  background-color: transparent;
  margin: 0;
  span {
    padding-right: 10px;
  }
}
</style>

